package com.clutch.student.Adapter;

/**
 * Created by clutchyu on 2018/3/17.
 */

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.clutch.student.Entity.Course;
import com.clutch.student.R;

import java.util.List;

/**
 *课程类适配器，将课程信息展示在CourseFragment上
 * 管理员查看所有课程信息
 */
public class MYCourseAdapter extends RecyclerView.Adapter<MYCourseAdapter.ViewHolder>{

    private List<Course> itemBeens;

    private LayoutInflater layoutInflater;

    public MYCourseAdapter(Context context, List<Course> courseList) {
        itemBeens = courseList;
        layoutInflater = LayoutInflater.from(context);
    }




    @Override
    public MYCourseAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = layoutInflater.inflate(R.layout.course_item, parent, false);
        ViewHolder vh = new ViewHolder(itemView);
        return vh;

    }

    @Override
    public void onBindViewHolder(MYCourseAdapter.ViewHolder holder, int position) {
        Course itemBean = itemBeens.get(position);
        final ViewHolder viewHolder = (ViewHolder) holder;
        viewHolder.dataIv.setImageResource(itemBean.getImageId());
        viewHolder.dataTv.setText(itemBean.getName());
    }

    @Override
    public int getItemCount() {
        if (itemBeens == null) {
            return 0;
        }
        return itemBeens.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        ImageView dataIv;
        TextView dataTv;
        public ViewHolder(View itemView) {
            super(itemView);
            dataIv = itemView.findViewById(R.id.Course_image);
            dataTv = (TextView) itemView.findViewById(R.id.Course_name);
        }
    }
}